package math

// 计算 array 的平均值

func MeanInt(a []int) float64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return float64(a[0])
	}

	var sum = float64(a[0])
	for i := 1; i < len(a); i++ {
		sum += float64(a[i])
	}

	return sum / float64(len(a))
}

func MeanInt64(a []int64) float64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return float64(a[0])
	}

	var sum = float64(a[0])
	for i := 1; i < len(a); i++ {
		sum += float64(a[i])
	}

	return sum / float64(len(a))
}

func MeanUInt(a []uint) float64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return float64(a[0])
	}

	var sum = float64(a[0])
	for i := 1; i < len(a); i++ {
		sum += float64(a[i])
	}

	return sum / float64(len(a))
}

func MeanUInt64(a []uint64) float64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return float64(a[0])
	}

	var sum = float64(a[0])
	for i := 1; i < len(a); i++ {
		sum += float64(a[i])
	}

	return sum / float64(len(a))
}

func MeanFloat64(a []float64) float64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return a[0]
	}

	var sum = a[0]
	for i := 1; i < len(a); i++ {
		sum += a[i]
	}

	return sum / float64(len(a))
}
